using FireStarterModeller.Logic.Commands;

namespace FireStarterModeller.UI.DetailsView.Controller
{
    public interface ISolutionViewController
    {
        void CreateAssembly(string assemblyName);
        void  SelectAssembly(SolutionViewModel.AssemblyModel assemblyModel);
        void DeleteAssembly(SolutionViewModel.AssemblyModel assemblyModel);
        void RenameAssembly(SolutionViewModel.AssemblyModel assemblyModel, string newName);

        void CreateClass(SolutionViewModel.AssemblyModel assemblyModel, string className);
        void SelectClass(SolutionViewModel.AssemblyModel assemblyModel, SolutionViewModel.ClassModel classModel);
        void DeleteClass(SolutionViewModel.ClassModel classModel);
        void RenameClass(SolutionViewModel.ClassModel classModel, string newClassName);
    }

    public class SolutionViewController : ISolutionViewController
    {
        private readonly ICommandFactory _commandFactory;
        private readonly ICommandRunner _commandRunner;
        private readonly SolutionViewModel _solutionViewModel;

        public SolutionViewController
            (ICommandFactory commandFactory, ICommandRunner commandRunner, SolutionViewModel projectViewModel)
        {
            _commandFactory = commandFactory;
            _commandRunner = commandRunner;
            _solutionViewModel = projectViewModel;
        }

        public void CreateAssembly(string assemblyName)
        {
            
            ICommand command = _commandFactory.CreateCreateAssembly(_solutionViewModel.DMSolution, assemblyName);
            _commandRunner.ApplyCommand(command);
        }

        public void SelectAssembly(SolutionViewModel.AssemblyModel assemblyModel)
        {
            _solutionViewModel.CurrentAssembly = assemblyModel;
        }

        public void DeleteAssembly(SolutionViewModel.AssemblyModel assemblyModel)
        {
            ICommand command = _commandFactory.CreateDeleteAssembly(assemblyModel.DMAssembly);
            _commandRunner.ApplyCommand(command);
        }

        public void RenameAssembly(SolutionViewModel.AssemblyModel assemblyModel, string newName)
        {
            ICommand command = _commandFactory.CreateRenameAssembly(assemblyModel.DMAssembly, newName);
            _commandRunner.ApplyCommand(command);
        }


        public void CreateClass(SolutionViewModel.AssemblyModel assemblyModel, string className)
        {
            ICommand command = _commandFactory.CreateCreateClass(assemblyModel.DMAssembly, className);
            _commandRunner.ApplyCommand(command);
        }

        public void SelectClass(SolutionViewModel.AssemblyModel assemblyModel, SolutionViewModel.ClassModel classModel)
        {
            assemblyModel.CurrentClass = classModel;
        }

        public void DeleteClass(SolutionViewModel.ClassModel classModel)
        {
            ICommand command = _commandFactory.CreateDeleteClass(classModel.DMClass);
            _commandRunner.ApplyCommand(command);
        }

        public void RenameClass(SolutionViewModel.ClassModel classModel, string newClassName)
        {
            ICommand command = _commandFactory.CreateRenameClass(classModel.DMClass, newClassName);
            _commandRunner.ApplyCommand(command);
        }
    }
}